class BootScene extends Phaser.Scene {
    constructor() {
        super('BootScene');
    }

    preload() {
        console.log('开始加载资源...');
        
        // 创建加载进度条背景
        const width = this.cameras.main.width;
        const height = this.cameras.main.height;
        
        // 进度条背景
        const progressBox = this.add.graphics();
        progressBox.fillStyle(0x222222, 0.8);
        progressBox.fillRect(width / 4, height / 2 - 30, width / 2, 50);
        
        // 进度条
        const progressBar = this.add.graphics();
        
        // 加载文本
        const loadingText = this.add.text(width / 2, height / 2 - 50, '加载中...', {
            font: '20px Arial',
            fill: '#ffffff'
        }).setOrigin(0.5, 0.5);
        
        // 百分比文本
        const percentText = this.add.text(width / 2, height / 2, '0%', {
            font: '18px Arial',
            fill: '#ffffff'
        }).setOrigin(0.5, 0.5);

        // 监听加载进度
        this.load.on('progress', (value) => {
            console.log('加载进度:', Math.floor(value * 100) + '%');
            percentText.setText(parseInt(value * 100) + '%');
            progressBar.clear();
            progressBar.fillStyle(0xffffff, 1);
            progressBar.fillRect(width / 4 + 10, height / 2 - 20, (width / 2 - 20) * value, 30);
        });
        
        // 加载完成时清除进度条
        this.load.on('complete', () => {
            console.log('资源加载完成');
            progressBar.destroy();
            progressBox.destroy();
            loadingText.destroy();
            percentText.destroy();
        });

        // 加载错误时
        this.load.on('loaderror', (file) => {
            console.error('加载错误:', file.src);
        });

        // 加载游戏资源
        this.load.image('background', 'assets/images/background.png');
        this.load.image('player', 'assets/images/player.png');
        this.load.image('enemy1', 'assets/images/enemy1.png');
        this.load.image('enemy2', 'assets/images/enemy2.png');
        this.load.image('enemy3', 'assets/images/enemy3.png');
        this.load.image('bullet', 'assets/images/bullet.png');
        this.load.image('powerup', 'assets/images/powerup.png');
    }

    create() {
        console.log('BootScene 创建完成，准备启动 MenuScene');
        // 启动菜单场景
        this.scene.start('MenuScene');
    }
} 